package com.cino.demos.shortlink.mq.consume;

import com.cino.demos.mapper.shortlink.ShortLinkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class shortlinkConsume {

    @Autowired
    private ShortLinkMapper shortLinkMapper;

    // RabbitListener 监听那个队列 simpleQueue队列名称
    // queuesToDeclare 如果监听的队列已存在就直接使用 如果不存在先创建再使用
    // 监听的队列中只要有消息 消费者就可以接收到
//    @RabbitListener(queuesToDeclare = @Queue(name = "Queue"))
//    public void receive(String msg,CorrelationData correlationData){
//        Link link = JSON.parseObject(msg, Link.class);
//        System.out.println("这个是消息id"+correlationData.getId());
//        shortLinkMapper.insert(link);
//
//    }


//    @RabbitListener(queuesToDeclare = @Queue(name = "Queue"))
//    public void receive(Message message) {
//        String msg = new String(message.getBody());
//        MessageProperties properties = message.getMessageProperties();
//        String correlationId = properties.getCorrelationId(); // 获取消息的 correlation ID
//        Link link = JSON.parseObject(msg, Link.class);
//        System.out.println("这个是消息id" + correlationId);
//        shortLinkMapper.insert(link);
//    }
}
